### -*- coding: utf-8 -*- #############################################
# Разработано Паэглит Арвидом (http://arvid.dp.ua/)
# Все права защищены, 2007
#
# Developed by Paeglit Arvid (http://arvid.dp.ua/)
# All right reserved, 2007
#######################################################################
"""Weibull factory for the Zope 3 based diplom.weibull package

$Id: expo.py 64 2007-12-28 18:34:23Z Arvi3D $
"""
__author__  = "Arvid"
__license__ = "GPL"
__version__ = "$Revision: 64 $"
__date__ = "$Date: 2007-12-28 20:34:23 +0200 (Fri, 28 Dec 2007) $"

from zope.interface import implements,implementedBy

from random import random, expovariate
from math import sqrt, exp, log

from diplom.interfaces import IDistributingFactory

class Weibull(object) :
    implements(IDistributingFactory)

    params = {
              'lambd': lambda data : (data.mean/2.0, 2.0*data.mean),
              'k': lambda data : (0, 2.0*data.mean)
              }

    def generate(self, lambd):
        """generate distributing variate"""
        return expovariate(lambd)

    def distributing(self, x, lambd):
        return x >= 0 and 1.0 - exp(-lambd*x) or 0

    def closeness(self, x, lambd):
        """closeness function"""
        return x >= 0 and lambd*exp(-lambd*x) or 0
